<?php

/**
 * 有权限全局集成类
 * @author wyb
 */

namespace Seller\Controller;

class BaseController extends CommController {

    protected $__seller_info = ''; //商家登录全局信息

    protected function _initialize() {
        parent::_initialize();
        $this->__checkedLogin();
        //获得商家配置
        $customer_setting = M('customer_setting')->where(array('customer_id' => $this->__seller_info['id']))->find();
        if ($customer_setting) {
            if ($customer_setting['row']) {
                $this->__row = $customer_setting['row'];
            }
            if ($customer_setting['goods_stock_warning']) {
                $this->__goods_stock_warning = $customer_setting['goods_stock_warning'];
            }
			if ($customer_setting['goods_advent_warning']) {
                $this->__goods_advent_warning = $customer_setting['goods_advent_warning'];
			}
        }
        if (!$customer_setting) {
            $customer_setting = array('acting' => 0, 'lock' => 0, 'wholesale' => 0, 'presell' => 0);
        }
        $this->assign('customer_setting', $customer_setting);
        $this->assign('login_info', $this->__seller_info);
        $this->assign('message_info', $this->__sellerMessageTotal());
    }

    /**
     * 获得商家总数
     */
    protected function __sellerMessageTotal() {
        $data['message'] = M('system_message')->where(array('target_id' => $this->__seller_info['id'], 'role' => 1, 'status' => 0))->count();
        $data['prompt'] = M('system_prompt')->where(array('customer_id' => $this->__seller_info['id'], 'status' => 0))->count();
        return $data;
    }

    /**
     * 获得支付方式
     */
    protected function __getCustomerPayment($supply_customer_id) {
        $payInfo = M('customer')->where(array('id' => $supply_customer_id))->field('weixin_pay_id,alipay_pay_id')->find();
        //如果没有配置支付 默认平台支付
        if (!$payInfo['weixin_pay_id']) {
            $payInfo['weixin_pay_id'] = M('payment_config')->where(array('type' => 2, 'default' => 1, 'status' => 1))->getField('id');
        }
        if (!$payInfo['alipay_pay_id']) {
            $payInfo['alipay_pay_id'] = M('payment_config')->where(array('type' => 1, 'default' => 1, 'status' => 1))->getField('id');
        }
        return $payInfo;
    }

}
